package org.mspring.mlog.service;

import java.util.Date;
import java.util.List;

import org.mspring.mlog.dao.TagDao;
import org.mspring.mlog.entity.Tag;
import org.mspring.platform.dao.Page;
import org.mspring.platform.dao.query.QueryBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Gao Youbo
 * @since 2012-7-24
 */
@Service
@Transactional
public class TagService {

    @Autowired
    private TagDao tagDao;

    public Page<Tag> listPage(QueryBuilder queryBuilder, Page<Tag> page) {
        return tagDao.listPage(queryBuilder, page);
    }

    public Tag get(long id) {
        return tagDao.get(id);
    }

    /**
     * 根据名字模糊查询
     *
     * @param name
     * @return
     */
    public List<Tag> listLikeByName(String name) {
        return tagDao.listLikeByName(name);
    }

    /**
     * 根据名字获取唯一的tag对象
     *
     * @param name
     * @return
     */
    public Tag findByName(String name) {
        return tagDao.findByName(name);
    }

    public void delete(Long... ids) {
        tagDao.delete(ids);
    }

    /**
     * 修改tag
     *
     * @param tag
     */

    public void update(Tag tag) {
        if (tag.getCreateTime() == null) {
            tag.setCreateTime(new Date());
        }
        tagDao.update(tag);
    }

    /**
     * 创建TAG
     *
     * @param tag
     * @return
     */

    public Long insert(Tag tag) {
        tag.setCreateTime(new Date());
        tag.setCount(new Long(0));
        return tagDao.insert(tag);
    }
}
